package com.rainng.coursesystem.controller.admin;

import com.rainng.coursesystem.controller.BaseController;
import com.rainng.coursesystem.model.shitong.*;
import com.rainng.coursesystem.model.vo.response.ResultVO;
import com.rainng.coursesystem.service.CheckFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.rainng.coursesystem.model.constant.GeneralReportProjectMap.*;


@Api(tags = "文件识别和校验接口")
@RequestMapping("/v2/file/check")
@RestController
public class CheckFileController extends BaseController {

    @Resource
    private CheckFileService service;

    @PostMapping("/na")
    public ResultVO selectNACodes(@RequestBody Map<String,String> vo) {
        return service.getNaCode(vo);
    }

    @PostMapping("/project")
    public ResultVO selectProjectsByVetype(@RequestBody VehicleTypeVo vo) {

        Map<String, String> h = new HashMap<>();
        if ("载货汽车".equals(vo.getVeType())) {
            h = H_PRJ_ONLINE;
        }
        if ("牵引车辆".equals(vo.getVeType())) {
            h = Q_PRJ_ONLINE;
        }
        if ("半挂车".equals(vo.getVeType())) {
            h = G_PRJ_ONLINE;
        }
        return super.result(h);
    }
    @PostMapping("/allProject")
    public ResultVO selectAllProjects() {

        Map<String, String> mergedMap = mergeMaps(H_PRJ_ONLINE, Q_PRJ_ONLINE, G_PRJ_ONLINE);
        /*if ("载货汽车".equals(vo.getVeType())) {
            h = H_PRJ_ONLINE;
        }
        if ("牵引车辆".equals(vo.getVeType())) {
            h = Q_PRJ_ONLINE;
        }
        if ("半挂车".equals(vo.getVeType())) {
            h = G_PRJ_ONLINE;
        }*/
        return super.result(mergedMap);
    }
    public static Map<String, String> mergeMaps(Map<String, String>... maps) {
        Map<String, String> mergedMap = new HashMap<>();
        for (Map<String, String> map : maps) {
            mergedMap.putAll(map);
        }
        return mergedMap;
    }
    @PostMapping("/page/count")
    @ApiOperation(value = "返回分页查询数量")
    public ResultVO listCount(@RequestBody CheckFileVo cvo) {
        return service.countCheckedFiles(cvo);
    }

    @PostMapping("/page")
    @ApiOperation(value = "分页查询")
    public ResultVO listPage(@RequestBody CheckFileVo cvo) {
        List<Object> lists = service.selectCheckedFiles(cvo);
        return super.result(lists);
    }

    @PostMapping("/confirm")
    @ApiOperation(value = "确认文件无误")
    public ResultVO confirmCheckDetail(@RequestBody CheckFileDetailVo vo) {
        ResultVO res = service.confirmFileInfoById(vo);
        return res;
    }

    @PostMapping("/update/valid/time")
    @ApiOperation(value = "编辑有效时间")
    public ResultVO updateValidtimeDetail(@RequestBody CheckFileUpdateVo vo) {
        ResultVO res = service.updateCheckedFilesValidTime(vo);
        return res;
    }

    @PostMapping("/update")
    @ApiOperation(value = "编辑")
    public ResultVO updateDetail(@RequestBody Map<String, String> vo) {
        Object res = service.updateCheckedFilesInfo(vo);
        return super.result(res);
    }

    @PostMapping("/detail/codes")
    @ApiOperation(value = "查看字段详情")
    public ResultVO getDetailCodes(@RequestBody CheckFileCodesVo cvo) {
        List<Map<String, String>> lists = service.getCodesByPrjNum(cvo);
        return super.result(lists);
    }
    @PostMapping("/detail/getDicCodes")
    @ApiOperation(value = "查看所有字段详情")
    public ResultVO getDicCodes() {
        List<Map<String, String>> lists = service.getDicCodes();
        return super.result(lists);
    }
    @PostMapping("/valid")
    @ApiOperation(value = "查看文件是否库中,0为未确认黄色,1为已确认绿色,2为不存在展示红色")
    public ResultVO checkFileInPrj(@RequestBody CheckFileColorVo cvo) {
        Map<String,Map<String,String>> res = service.checkFileColor(cvo);
        return super.result(res);
    }

    @PostMapping("/detail")
    @ApiOperation(value = "查看详情")
    public ResultVO getDetail(@RequestBody CheckFileDetailByNameVo vo) {
        Map<String, String> res = service.selectFileInfoById(vo);
        return super.result(res);
    }
}
